"""
结算参数接口模块
设置收货地址/设置支付方式/查看会员订单列表/取消订单/确认收货/评论相关
"""
from api.base import BaseBuyerApi
from api.buyer.login_api import BuyerLoginAPI


class BuyerController(BaseBuyerApi):
    """设置收货地址"""
    def __init__(self,address_id):
        super().__init__()
        self.method = "post"
        self.url = f'{self.host}/trade/checkout-params/address-id/{address_id}'

class Payment_type(BaseBuyerApi):
    """设置支付方式"""
    def __init__(self,payment_type="COD"):
        super().__init__()
        self.method = "post"
        self.url = f'{self.host}/trade/checkout-params/payment-type'
        self.data = {
            "payment_type": payment_type
        }

class Search_order(BaseBuyerApi):
    """查看会员订单列表"""
    def __init__(self,page_no=1, page_size=5, order_status="WAIT_SHIP", key_words="沙陌",
                 start_time="", end_time=""):
        super().__init__()
        self.method = "post"
        self.url = f'{self.host}/trade/orders'
        # 表单参数
        self.data = {
            "page_no": page_no,
            "page_size": page_size,
            "order_status": order_status,
            "key_words": key_words,  # 搜索商品名称
            "start_time": start_time,  # 时间戳
            "end_time": end_time  # 时间戳
        }

class Cancel_order(BaseBuyerApi):
    """取消订单"""
    def __init__(self,order_sn,reason="没啥原因，就是不想要了"):
        super().__init__()
        self.url = f'{self.host}/trade/orders/{order_sn}/cancel'
        # 表单参数
        self.data = {
            "reason": reason
        }

class Confirm_rog_order(BaseBuyerApi):
    """确认收货"""
    def __init__(self,order_sn):
        super().__init__()
        self.method = "post"
        self.url = f'{self.host}/trade/orders/{order_sn}/rog'


class Member_comment(BaseBuyerApi):
    """提交评论"""
    def __init__(self,sku_id,order_sn):
        super().__init__()
        self.method = "post"
        self.url = f'{self.host}/members/comments'
        self.data = {
            "order_sn": order_sn,
            "delivery_score": 5,
            "description_score": 5,
            "service_score": 5,
            "comments": [{
                "sku_id": sku_id,
                "content": "这是我的评论",
                "grade": "good",
                "images": []
            }]
        }

class Member_address(BaseBuyerApi):
    """添加会员地址"""
    def __init__(self,name="罗华",mobile="15723236309"):
        super().__init__()
        self.method = "post"
        self.url = f"{self.host}/members/address"
        self.data = {
            "def_addr": 0,
            "ship_address_name":"",
            "name": name,
            "mobile": mobile,
            "region": "13521",
            "addr": 1111
            }

class Select_address_id(BaseBuyerApi):
    """查询当前会员的某个地址"""
    def __init__(self,id):
        super().__init__()
        self.method = "get"
        self.url = f"{self.host}/members/address/{id}"

class Put_address_id(BaseBuyerApi):
    """修改会员地址"""
    # def __init__(self,id,name="罗华",mobile="15723236309"):
    def __init__(self, id):
        super().__init__()
        self.method = "put"
        self.url = f"{self.host}/members/address/{id}"
        self.data = {
            "def_addr": 0,
            "ship_address_name":"",
            "name":"罗华",
            "mobile": "15723236309",
            "region": "13521",
            "addr": 1111
            }

class Delete_address_id(BaseBuyerApi):
    """删除会员地址"""
    def __init__(self,id):
        super().__init__()
        self.method = "delete"
        self.url = f"{self.host}/members/address/{id}"

class put_address_id_default(BaseBuyerApi):
    """设置地址为默认地址"""
    def __init__(self,id):
        super().__init__()
        self.method = "put"
        self.url = f"{self.host}/members/address/{id}/default"

class Select_address(BaseBuyerApi):
    """查询当前会员地址列表"""
    def __init__(self):
        super().__init__()
        self.method = "get"
        self.url = f"{self.host}/members/addresses"


if __name__ == '__main__':
    # resp = BuyerLoginAPI().request()
    # print(resp.json())
    # BaseBuyerApi.buy_token = resp.json()['access_token']
    # resp = Member_comment().request()
    # print(resp.json())
    resp = Select_address().request()
    print(resp.json())